home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_313 / uucp / uucp1.lzh / src / uucico / uux.c < prev    next >
C/C++ Source or Header  |  1990-01-25  |  3KB  |  198 lines

  1.  
  2. /*
  3.  *  UUX.C by William Loftus
  4.  *  Copyright 1988 by William Loftus.    All rights reserved.
  5.  *
  6.  *  Example: 1> uux mail-message "burdvax!rmail wpl"
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include "/version.h"
  12.  
  13. IDENT(".01");
  14.  
  15. char user[128];
  16. char file_name[128];
  17. char command[128];
  18.  
  19. char exec_file[128];
  20. char x_exec_file[128];
  21. char command_file[128];
  22. char data_file[128];
  23. int seq;
  24.  
  25. char path[128];
  26.  
  27. void read_ctl();
  28. void GetTo();
  29. void GetSubject();
  30.  
  31. #define TRUE 1
  32. #define FALSE 0
  33.  
  34. CXBRK()
  35. {
  36.     return(0);
  37. }
  38.  
  39. void
  40. main(argc, argv)
  41. int argc;
  42. char **argv;
  43. {
  44.     int error;
  45.  
  46.     getcwd(path,128);
  47.     chdir("UUSPOOL:");
  48.     read_ctl();
  49.     if (argc == 3) {
  50.     strcpy(file_name, argv[1]);
  51.     strcpy(command, argv[2]);
  52.     } else {
  53.     printf("Usage: uux file-name command\n");
  54.     printf("Example: 1> uux mail-message \"burdvax!rmail wpl\"\n");
  55.     chdir(path);
  56.     exit(1);
  57.     }
  58.     seq = GetSequence(4);
  59.     if (seq >= 0)
  60.     error = Queue();
  61.     UnLockFile(exec_file);
  62.     UnLockFile(x_exec_file);
  63.     UnLockFile(command_file);
  64.     UnLockFile(data_file);
  65.     chdir(path);
  66.     if (seq < 0 || error < 0)
  67.     exit(1);
  68. }
  69.  
  70. Queue()
  71. {
  72.     FILE *fp;
  73.     char system_name[32];
  74.     int bang;
  75.     int error;
  76.  
  77.     bang = (int)strchr(command,'!');
  78.     bang = bang - (int)command;
  79.  
  80.     strncpy(system_name,command,bang);
  81.  
  82.     system_name[bang] = '\0';
  83.  
  84.     if (!is_in_L_sys_file(system_name)) {
  85.     printf ("System \"%s\" not in L.sys file.\n", system_name);
  86.     return(-1);
  87.     }
  88.  
  89.     system_name[7] = '\0';
  90.  
  91.     sprintf(exec_file,"D.%sX%04d", system_name, seq++);
  92.     sprintf(x_exec_file,"X.%sX%04d", system_name, seq++);
  93.     sprintf(command_file,"C.%sA%04d", system_name, seq++);
  94.     sprintf(data_file,"D.%sB%04d", system_name, seq);
  95.  
  96.     LockFile(exec_file);
  97.     LockFile(x_exec_file);
  98.     LockFile(command_file);
  99.     LockFile(data_file);
  100.  
  101.     fp = fopen(exec_file,"w");
  102.     if (fp) {
  103.     fprintf(fp,"U %s\n", user);
  104.     fprintf(fp,"F %s\n", data_file);
  105.     fprintf(fp,"I %s\n", data_file);
  106.     fprintf(fp,"C %s\n", (char *)command + bang + 1);
  107.     fclose(fp);
  108.     } else {
  109.     perror(exec_file);
  110.     return(-1);
  111.     }
  112.  
  113.     fp = fopen(command_file,"w");
  114.     if (fp) {
  115.     fprintf(fp,"S %s %s %s - %s 0666\n",
  116.         data_file,
  117.         data_file,
  118.         user,
  119.         data_file
  120.     );
  121.     fprintf(fp,"S %s %s %s - %s 0666\n",
  122.         exec_file,
  123.         x_exec_file,
  124.         user,
  125.         exec_file
  126.     );
  127.     fclose(fp);
  128.     } else {
  129.     perror(command_file);
  130.     return(-1);
  131.     }
  132.     chdir(path);
  133.     error =  Copy(file_name, data_file);
  134.     chdir("UUSPOOL:");
  135.     return(error);
  136. }
  137.  
  138. /*
  139.  * Read the control file and grab a few parameters.
  140.  */
  141.  
  142. #define CTL_DELIM " \t\n\r"
  143.  
  144. void
  145. read_ctl()
  146. {
  147.     FILE  *fd;
  148.     static char  buf[128];
  149.  
  150.     if (! (fd = fopen("UULIB:config", "r"))) {
  151.     printf("Can't Find config file");
  152.     perror("config");
  153.     chdir(path);
  154.     exit(3);
  155.     }
  156.  
  157.     while (NULL != fgets(buf, sizeof buf, fd)) {
  158.     if (strncmp(buf, "UserName", 8) == 0)
  159.         strcpy(user, strtok(&buf[9], CTL_DELIM));
  160.     }
  161.     fclose(fd);
  162. }
  163.  
  164. Copy(from, to)
  165. char *from;
  166. char *to;
  167. {
  168.     FILE *fd;
  169.     FILE *td;
  170.     int c;
  171.     static char to_buf[128];
  172.  
  173.     fd = fopen(from, "r");
  174.     if (!fd) {
  175.     printf("Could not open %s.\n", from);
  176.     perror(from);
  177.     return(-1);
  178.     }
  179.  
  180.     strcpy(to_buf, "UUSPOOL:");
  181.     strcat(to_buf, to);
  182.  
  183.     td = fopen(to_buf, "w");
  184.     if (!td) {
  185.     printf("Could not open %s.\n", to_buf);
  186.     perror(to);
  187.     return(-1);
  188.     }
  189.     while ((c = fgetc(fd)) != EOF) {
  190.     fputc((char)c, td);
  191.     }
  192.     fclose(fd);
  193.     fclose(td);
  194.     return(1);
  195. }
  196.  
  197.  
  198.